package edu.udlap.spring2008.is300.finalexam.app.mvc.view;

import edu.udlap.spring2008.is300.finalexam.framework.mvc.model.ModelState;
import edu.udlap.spring2008.is300.finalexam.framework.mvc.view.ViewComponent;
import edu.udlap.spring2008.is300.finalexam.framework.mvc.view.ViewCompositeComponent;
import java.awt.Component;
import java.awt.GridLayout;
import javax.swing.JPanel;

/**
 *
 * @author Ruslán Ledesma Garza
 */
public class ViewModeSwitchPanel extends ViewCompositeComponent
{

    protected JPanel mainPanel_ = new JPanel();
    protected ViewComponent gridModeChild_;
    protected ViewComponent slideShowModeChild_;
    
    protected boolean gridModeChildIsDefault_;

    public ViewModeSwitchPanel(boolean gridModeChildIsDefault)
    {
        gridModeChildIsDefault_ = gridModeChildIsDefault;
        mainPanel_.setLayout(new GridLayout());
    }       
    
    public void addGridModeChild(ViewComponent child)
    {
        super.addChild(child);
        
        gridModeChild_ = child;
    }
    
    public void addSlideShowModeChild(ViewComponent child)
    {
        super.addChild(child);
        
        slideShowModeChild_ = child;
    }

    @Override
    public void setInitialState(ModelState modelState)
    {
        if(gridModeChildIsDefault_)
            mainPanel_.add(gridModeChild_.getComponent());
        else
            mainPanel_.add(slideShowModeChild_.getComponent());
        
        super.setInitialState(modelState);
    }
    
    @Override
    public void addChild(ViewComponent child)
    {
    }

    @Override
    public void gridMode()
    {
        mainPanel_.remove(slideShowModeChild_.getComponent());
        mainPanel_.add(gridModeChild_.getComponent());
        
        //gridModeChild_.getComponent().repaint();
        mainPanel_.validate();
        mainPanel_.repaint();
        
        super.gridMode();
    }

    @Override
    public void slideShowMode()
    {
        mainPanel_.remove(gridModeChild_.getComponent());
        mainPanel_.add(slideShowModeChild_.getComponent());

        //slideShowModeChild_.getComponent().repaint();
        mainPanel_.validate();
        mainPanel_.repaint();
        
        super.slideShowMode();
    }
    
    @Override
    public Component getComponent()
    {
        return (Component)mainPanel_;
    }

}
